package com.apexwear.apexutils.adapter;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.apexwear.apexutils.R;

public class AdapterSelectDialog extends RecyclerView.Adapter<AdapterSelectDialog.PageHold> {
    String[] pagesList;
    Context mContext;

    public AdapterSelectDialog(String[] pagesList, Context mContext) {
        this.pagesList = pagesList;
        this.mContext = mContext;
    }

    @NonNull
    @Override
    public PageHold onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View adapterView = LayoutInflater.from(mContext).inflate(R.layout.adapter_dialog_select_list, parent, false);
        return new PageHold(adapterView);
    }

    @Override
    public void onBindViewHolder(@NonNull PageHold holder, int position) {
        if (pagesList == null || pagesList.length == 0) {
            return;
        }
        holder.txtText.setText(pagesList[position]);

    }

    @Override
    public int getItemCount() {
        return pagesList == null ? 0 : pagesList.length;
    }

    class PageHold extends RecyclerView.ViewHolder {
        TextView txtText;

        public PageHold(@NonNull View itemView) {
            super(itemView);
            txtText = itemView.findViewById(R.id.text_page);
        }
    }

    public void destroyAdapter() {
        mContext = null;
        pagesList = null;
    }
}
